/*******************************************************************************
 *
 *    Copyright (c) Dolphin Browser
 *
 *    ViewTest
 *    
 *    PageView
 *    TODO File description or class description.
 *
 *    @author: derron
 *    @since:  2010-3-8
 *    @version: 1.0
 *
 ******************************************************************************/
package com.sdk.widget.threescreen.scrollview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;

public class PageView extends FrameLayout {
	private View child;
	private boolean dimensionChanged;
	private int pageHeight;
	private int pageNumber;
	private int pageWidth;

	public PageView(Context context) {
		super(context);
		init(context);
	}

	public PageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	private void init(Context context){
		setFocusable(true);
		setVerticalScrollBarEnabled(false);
		setHorizontalScrollBarEnabled(false);
	}

	public boolean dispatchTouchEvent(MotionEvent paramMotionEvent) {
		super.dispatchTouchEvent(paramMotionEvent);
		return true;
	}

	public int getPageNumber() {
		return this.pageNumber;
	}

	protected void onMeasure(int paramInt1, int paramInt2) {
		int k = View.MeasureSpec.makeMeasureSpec(pageWidth,
				MeasureSpec.EXACTLY);
		int l = View.MeasureSpec.makeMeasureSpec(pageHeight,
				MeasureSpec.EXACTLY);
		if (!dimensionChanged
				&& (((getChildCount() != 0) || (null == child)))) {
			View localView1 = this.child;
			View localView2 = getChildAt(0);
			if (localView1 == localView2) {
				setMeasuredDimension(pageWidth, pageHeight);
				if(child != null){
					child.measure(k, l);
				}
				return;
			}
		}
		super.onMeasure(k, l);
		this.dimensionChanged = false;
		if (getChildCount() > 0) {
			child = getChildAt(0);
		} else {
			child = null;
		}
		setMeasuredDimension(pageWidth, pageHeight);
		if(child != null){
			child.measure(k, l);
		}
	}

	public void setPageDimension(int paramInt1, int paramInt2) {
		if ((this.pageWidth == paramInt1) && (this.pageHeight == paramInt2))
			return;
		this.pageWidth = paramInt1;
		this.pageHeight = paramInt2;
		this.dimensionChanged = true;
	}

	public void setPageNumber(int paramInt) {
		this.pageNumber = paramInt;
	}
}
